import { plan } from '../server/plan.js';


// 获取所有目标
export async function getPlanList(self) {
    try {
        let res = await plan.getPlanList();
        if (res.success) {
            let allTarget = [];
            for (let i = 0; i < res.planList.length; i++) {
                let item = res.planList[i];
                let plan = {
                    id: item.id,
                    icon: '',
                    title: item.name,
                    checkinDay: item.checkinDay,
                    count: item.count,
                    progress: `${((parseInt(item.checkinDay) / parseInt(item.count)) * 100).toFixed(2)}%`,
                    isChecked: item.isCheckin
                };
                allTarget.push(plan);
            }
            self.allTarget = allTarget;
        }
    } catch (err) {
        console.log(err);
    }
}

// 筛选不同的目标
export const filterPlanList = {
    '全部': (planList) => {
        return planList;
    },
    '进行中': (planList) => {
        return planList.filter(item => {
            return parseInt(item.checkinDay) !== parseInt(item.count);
        });
    },
    '已完成': (planList) => {
        return planList.filter(item => {
            return parseInt(item.checkinDay) === parseInt(item.count);
        });
    }
};